package com.lyswkjxgs.report.controller;

import com.lyswkjxgs.report.domain.AjaxResult;
import com.lyswkjxgs.report.domain.ConfigDTO;
import com.lyswkjxgs.report.domain.ReportParam;
import com.lyswkjxgs.report.service.ReportService;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class ReportController {

    @Autowired
    private ReportService reportService;

    private Logger logger = LoggerFactory.getLogger(getClass());
    @PostMapping(value = "/api/report/get")
    public AjaxResult<List<Map<String, Object>>> getReport(@RequestBody ReportParam reportParam){
        return AjaxResult.successData(reportService.getReport(reportParam));
    }

    @PostMapping(value = "/api/report/export")
    public void export(@RequestBody ReportParam reportParam, HttpServletResponse response) throws Exception{
        try {
            reportService.export(reportParam, response);
        }
        catch (Exception e){
            response.sendError(500, e.getMessage());
            logger.warn("导出异常", e);
        }
    }

}
